package com.jingdianjichi.oss.service;

import com.sun.corba.se.impl.encoding.BufferQueue;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * ClassName:FileService
 * Package:com.jingdianjichi.oss.service
 * Description:
 *
 * @Author fst
 * @Create 2024/10/3 21:39
 * @Version 1.0
 */
@Service
public class FileService
{
   private final StorageAdapter storageAdapter;

   public FileService(StorageAdapter storageAdapter)
   {
       this.storageAdapter = storageAdapter;
   }

   public List<String> getAllBucket()
   {
       return storageAdapter.getAllBucket();
   }

    public String getUrl(String bucketName, String objectName)
    {
        return storageAdapter.getUrl(bucketName,objectName);
    }

    public String uploadFile(MultipartFile uploadFile,String bucket,String objectName)
    {
        storageAdapter.uploadFile(uploadFile, bucket,objectName);
        objectName = objectName + "/" + uploadFile.getOriginalFilename();
        return storageAdapter.getUrl(bucket,objectName);
    }
}
